home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / emacs_src_18_58.lha / emacs-18.58 / lisp / echistory.el < prev    next >
Lisp/Scheme  |  1992-02-21  |  7KB  |  150 lines

  1. ;; Electric Command History Mode
  2. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  3. ;; Principal author K. Shane Hartman
  4.  
  5. ;; This file is part of GNU Emacs.
  6.  
  7. ;; GNU Emacs is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation; either version 1, or (at your option)
  10. ;; any later version.
  11.  
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ;; GNU General Public License for more details.
  16.  
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  19. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  
  22. (require 'electric)            ; command loop
  23. (require 'chistory)            ; history lister
  24.  
  25. (defun Electric-command-history-redo-expression (&optional noconfirm)
  26.   "Edit current history line in minibuffer and execute result.
  27. With prefix argument NOCONFIRM, execute current line as is without editing."
  28.   (interactive "P")
  29.   (let (todo)
  30.     (save-excursion
  31.       (set-buffer "*Command History*")
  32.       (beginning-of-line)
  33.       (setq todo (read (current-buffer)))
  34.       (if (boundp 'electric-history-in-progress)
  35.       (if todo (throw 'electric-history-quit (list noconfirm todo)))))))
  36.  
  37. (defvar electric-history-map ())
  38. (if electric-history-map
  39.     ()
  40.   (setq electric-history-map (make-keymap))
  41.   (fillarray electric-history-map 'Electric-history-undefined)
  42.   (define-key electric-history-map "\e" (make-keymap))
  43.   (fillarray (lookup-key electric-history-map "\e") 'Electric-history-undefined)
  44.   (define-key electric-history-map "\C-u" 'universal-argument)
  45.   (define-key electric-history-map " " 'Electric-command-history-redo-expression)
  46.   (define-key electric-history-map "!" 'Electric-command-history-redo-expression)
  47.   (define-key electric-history-map "\e\C-x" 'eval-sexp)
  48.   (define-key electric-history-map "\e\C-d" 'down-list)
  49.   (define-key electric-history-map "\e\C-u" 'backward-up-list)
  50.   (define-key electric-history-map "\e\C-b" 'backward-sexp)
  51.   (define-key electric-history-map "\e\C-f" 'forward-sexp)
  52.   (define-key electric-history-map "\e\C-a" 'beginning-of-defun)
  53.   (define-key electric-history-map "\e\C-e" 'end-of-defun)
  54.   (define-key electric-history-map "\e\C-n" 'forward-list)
  55.   (define-key electric-history-map "\e\C-p" 'backward-list)
  56.   (define-key electric-history-map "q" 'Electric-history-quit)
  57.   (define-key electric-history-map "\C-c" nil)
  58.   (define-key electric-history-map "\C-c\C-c" 'Electric-history-quit)
  59.   (define-key electric-history-map "\C-]" 'Electric-history-quit)
  60.   (define-key electric-history-map "\C-z" 'suspend-emacs)
  61.   (define-key electric-history-map "\C-h" 'Helper-help)
  62.   (define-key electric-history-map "?" 'Helper-describe-bindings)
  63.   (define-key electric-history-map "\e>" 'end-of-buffer)
  64.   (define-key electric-history-map "\e<" 'beginning-of-buffer)
  65.   (define-key electric-history-map "\n" 'next-line)
  66.   (define-key electric-history-map "\r" 'next-line)
  67.   (define-key electric-history-map "\177" 'previous-line)  
  68.   (define-key electric-history-map "\C-n" 'next-line)
  69.   (define-key electric-history-map "\C-p" 'previous-line)
  70.   (define-key electric-history-map "\ev" 'scroll-down)
  71.   (define-key electric-history-map "\C-v" 'scroll-up)
  72.   (define-key electric-history-map "\C-l" 'recenter)
  73.   (define-key electric-history-map "\e\C-v" 'scroll-other-window))
  74.  
  75. (defvar electric-command-history-hook nil
  76.   "If non-nil, its value is called by  electric-command-history.")
  77.  
  78. (defun electric-command-history ()
  79.   "Major mode for examining and redoing commands from  command-history.
  80. The number of command listed is controlled by  list-command-history-max.
  81. The command history is filtered by  list-command-history-filter  if non-nil.
  82. Combines typeout Command History list window with menu like selection
  83. of an expression from the history for re-evaluation in the *original* buffer.
  84.  
  85. The history displayed is filtered by  list-command-history-filter  if non-nil.
  86.  
  87. This pops up a window with the Command History listing.  If the very
  88. next character typed is Space, the listing is killed and the previous
  89. window configuration is restored.  Otherwise, you can browse in the
  90. Command History with  Return  moving down and  Delete  moving up, possibly
  91. selecting an expression to be redone with Space or quitting with `Q'.
  92.  
  93. Like Emacs-Lisp Mode except that characters do not insert themselves and
  94. Tab and linefeed do not indent.  Instead these commands are provided:
  95. Space or !    edit then evaluate current line in history inside
  96.            the ORIGINAL buffer which invoked this mode.
  97.            The previous window configuration is restored
  98.            unless the invoked command changes it.
  99. C-c C-c, C-], Q    Quit and restore previous window configuration.
  100. LFD, RET    Move to the next line in the history.
  101. DEL        Move to the previous line in the history.
  102. ?        Provides a complete list of commands.
  103.  
  104. Calls the value of  electric-command-history-hook  if that is non-nil
  105. The Command History listing is recomputed each time this mode is invoked."
  106.   (interactive)
  107.   (let ((electric-history-in-progress t)
  108.     (old-buffer (current-buffer))
  109.     (todo))
  110.     (unwind-protect
  111.     (setq todo
  112.           (catch 'electric-history-quit
  113.         (save-window-excursion
  114.           (save-window-excursion
  115.             (list-command-history)
  116.             (set-buffer "*Command History*")
  117.             (Command-history-setup 'electric-command-history
  118.                        "Electric History"
  119.                        electric-history-map))
  120.           (Electric-pop-up-window "*Command History*")
  121.           (run-hooks 'electric-command-history-hook)
  122.           (if (eobp)
  123.               (progn (ding)
  124.                  (message "No command history.")
  125.                  (throw 'electric-history-quit nil))
  126.             (let ((Helper-return-blurb "return to History"))
  127.               (Electric-command-loop 'electric-history-quit
  128.                          "->" t))))))
  129.       (set-buffer "*Command History*")
  130.       (Command-history-setup)
  131.       (bury-buffer (current-buffer)))
  132.     (if (consp todo)
  133.     (progn (set-buffer old-buffer)
  134.            (if (car todo)
  135.            (apply (car (car (cdr todo))) (cdr (car (cdr todo))))
  136.          (edit-and-eval-command "Redo: " (car (cdr todo))))))))
  137.  
  138. (defun Electric-history-undefined ()
  139.   (interactive)
  140.   (ding)
  141.   (message "Type C-h for help, ? for commands, C-c to quit, Space to execute")
  142.   (sit-for 4))
  143.  
  144. (defun Electric-history-quit ()
  145.   "Quit Electric Command History, restoring previous window configuration."
  146.   (interactive)
  147.   (if (boundp 'electric-history-in-progress)
  148.       (progn (message "")
  149.          (throw 'electric-history-quit nil))))
  150.